package com.ocom.payconfig.dao;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.ocom.common.entity.human.EntityPersonnelInfo;
import com.ocom.common.request.payconfig.AddSubsidyDataResquest;
import com.ocom.common.vo.payconfig.PersonAndDeptVo;
import icu.mhb.mybatisplus.plugln.base.mapper.JoinBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


@Mapper
public interface IDaoPersonnelInfo extends JoinBaseMapper<EntityPersonnelInfo> {

    @Select({"<script>",
                    "select  p.p_id \n" +
                    "FROM personnel_info p INNER join  xf_account_info a on p.p_id = a.p_id  \n" +
                    "where p.com_id=#{comId} " +
                    "and p.status = 0 " +
                    "and a.account_state =0 " +
                    "and a.acc_type_id =#{accType} " +
                    " <when test=\"deptIdList.size()>0 \" > "+
                    "AND  p.dept_id in " +
                    "<foreach collection='deptIdList' item='item' open='(' separator=',' close=')'>" +
                        "#{item}" +
                    "</foreach>"+
                    " </when> "+
                    " <when test='pTags != null' > "+
                    "<foreach collection='pTags' item='item' open=' AND  p.p_tags IS NOT NULL and (' separator='or' close=')'>" +
                    "  p.p_tags  like CONCAT(CONCAT('%,', #{item}), ',%') " +
                    "</foreach>"+
                    " </when> "+
            "</script>"})
    public List<EntityPersonnelInfo> selectPersonVo(AddSubsidyDataResquest addSubsidyDataResquest);


    @Select({"<script>",
            "select  p.p_id \n" +
                    "FROM personnel_info p INNER join  xf_account_info a on p.p_id = a.p_id  \n" +
                    "where p.com_id=#{comId} " +
                    "and p.status = 0 " +
                    "and a.account_state =0 " +
                    "and a.acc_type_id in " +
                    "<foreach collection='accType' item='item' open='(' separator=',' close=')'>" +
                    "#{item} " +
                    "</foreach> "+
                    " <when test=\" deptIdList != null and deptIdList.size() > 0 \" > "+
                    "AND  p.dept_id in " +
                    "<foreach collection='deptIdList' item='item' open='(' separator=',' close=')'>" +
                    "#{item}" +
                    "</foreach>"+
                    " </when> "+
                    " <when test='pTags != null and pTags.size() > 0' > "+
                    "<foreach collection='pTags' item='item' open=' AND  p.p_tags IS NOT NULL and (' separator='or' close=')'>" +
                    "  p.p_tags  like CONCAT(CONCAT('%,', #{item}), ',%') " +
                    "</foreach>"+
                    " </when> "+
                    "</script>"})
    public List<EntityPersonnelInfo> selectPersonAndAccount(@Param("comId") Long comId, @Param("accType") List<Integer> accType, @Param("deptIdList") List<String> deptIdList,  @Param("pTags")List<String> pTags);


    @Select({"<script>",
            "select  a.acc_type_id  as pType,count(*) as cardState  from   personnel_info  p \n" +
                    "left  join    xf_account_info  a  on p.com_id=a.com_id  and p.p_id=a.p_id\n" +
                    " where p.com_id=#{comId}  and p.status=0 \n" +
                    " group  by a.acc_type_id "+
                    "</script>"})
    public List<EntityPersonnelInfo> totalNumberPerson(@Param("comId") Long comId);

    @Select("select p.p_id  , p.dept_id ,p.p_code,p.p_name,d.dept_name " +
            "from personnel_info  p left  join  dept_info d on p.com_id =d.com_id  and p.dept_id =d.dept_id  ${ew.customSqlSegment}")
    public PersonAndDeptVo selectPerson(@Param(Constants.WRAPPER) Wrapper wrapper);
}
